Skip to content

πŸ“¦ Trim npm package size (521 KB β†’ 213 KB, no runtime change)#1206

Merged
taras merged 1 commit into
v4from
bundle-size-experiment
Jul 5, 2026
Merged

πŸ“¦ Trim npm package size (521 KB β†’ 213 KB, no runtime change)#1206
taras merged 1 commit into
v4from
bundle-size-experiment

Conversation

@taras

@taras taras commented Jul 5, 2026

Copy link
Copy Markdown
Member

Motivation

pkg-size.dev/effection reports the published package at ~580 KB, which looks alarming. On inspection almost all of it is install-only dev artifacts, not code that lands in a consumer's app bundle β€” the runtime cost a bundler actually pulls in was already optimal at ~5.8 KB min+gzip. The tarball was ~30% sourcemaps, ~20% duplicated .d.ts (emitted into both esm/ and script/), and ~18% raw TS source β€” none of which a bundler loads. This PR trims that fat without touching the code consumers run.

Approach

Three dnt build options in tasks/build-npm.ts:

Option Effect
sourceMap: false stop shipping .js.map (no runtime value)
declaration: "separate" emit .d.ts once into a shared types/ folder instead of duplicating across esm/ and script/
skipSourceOutput: true stop shipping raw src/*.ts

Works on the currently pinned dnt 0.41.3 β€” no toolchain bump required.

Measured (via npm pack)

Metric Before After Ξ”
unpacked on disk 521 KB 213 KB βˆ’59%
files 427 145 βˆ’66%
download (.tgz gzip) 80 KB 40 KB βˆ’49%
runtime bundle (min+gzip) 5.8 KB 5.8 KB unchanged

Verified

  • βœ… ESM import { run, sleep } from "effection" runs
  • βœ… CJS require("effection") runs (CJS output preserved)
  • βœ… tsc --noEmit resolves types against the new shared types/ folder

Notes / decisions

  • deno bundle --declaration (the "bundled single .d.ts" idea) was evaluated and rejected: it can't type-check effection's cross-runtime lib/main.ts (uses Deno.*, DOM, and a node:process dynamic import at once β€” no single lib satisfies all three), and pre-bundling gave no runtime-size win since bundlers already tree-shake the modular output.
  • sourceMap: false is the one debatable line β€” it drops the biggest chunk (157 KB) but also removes published debugging maps. If shipping sourcemaps is preferred, revert just that line (unpacked lands at ~370 KB instead of 213 KB).

Shrinks the published `effection` npm package without touching the code
consumers actually run.

Three dnt build options in tasks/build-npm.ts:
- `sourceMap: false`  β€” stop shipping `.js.map` (no runtime value)
- `declaration: "separate"` β€” emit `.d.ts` once into a shared `types/`
  folder instead of duplicating across `esm/` and `script/`
- `skipSourceOutput: true` β€” stop shipping raw `src/*.ts`

Measured (npm pack):
- unpacked on disk: 521 KB -> 213 KB (-59%), 427 -> 145 files
- download (.tgz):   80 KB -> 40 KB (-49%)
- runtime bundle (min+gzip): 5.8 KB, unchanged

The 5.8 KB a bundler pulls into an app was already optimal; the old
580 KB was install-only dev artifacts (sourcemaps, per-module dup'd
declarations, raw TS source) that no app bundle loads. Verified ESM
import, CJS require, and `tsc` type resolution all still pass. Works on
the currently pinned dnt 0.41.3 β€” no toolchain bump required.
@pkg-pr-new

pkg-pr-new Bot commented Jul 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/effection@1206

commit: fe1198b

@codspeed-hq

codspeed-hq Bot commented Jul 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

βœ… 6 untouched benchmarks


Comparing bundle-size-experiment (fe1198b) with v4 (56af00f)

Open in CodSpeed

@taras taras merged commit 4f400d0 into v4 Jul 5, 2026
19 checks passed
@taras taras deleted the bundle-size-experiment branch July 5, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants